<?php
abstract class MenuItemActiveRecord extends CActiveRecord{

    protected function purify($text)
    {
        $p = new CHtmlPurifier;
        $p->options = array(
            'HTML.SafeObject'=>true,
            'Output.FlashCompat'=>true,
        );
        return $p->purify($text);
    }

    protected function beforeSave()
    {
        if(parent::beforeSave())
        {
            $this->link_path = mb_strtolower($this->link_path);
            $this->title= $this->purify($this->title);
            $this->type = $this->purify($this->type);

            if(!$this->isNewRecord)
            {
                if($this->type === 'list-all-categories' || $this->type === 'list-all-articles')
                {
                    $this->params = 0;
                }
            }
            return true;
        }
        else
            return false;
    }



    public function behaviors()
    {
        return array(
            'CTimestampBehavior' => array(
                'class'=>'zii.behaviors.CTimestampBehavior',
                'createAttribute' => 'create_time',
                'updateAttribute' => 'update_time',
                'setUpdateOnCreate' => true,
            )
        );
    }
}